Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ce/connect messaging #35364

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open

Ce/connect messaging #35364

wants to merge 57 commits into from

Conversation

calellowitz
Copy link
Contributor

@calellowitz calellowitz commented Nov 14, 2024

Product Description

This adds connect messaging as a new message type in the messaging framework. It does not currently support form sessions although I will add those prior to merge. That said, I wanted to open this up to review now since it is quite large and touches a fair amount of complex code.

Technical Summary

Tech Spec: https://docs.google.com/document/d/1FgsXr0PLR7Btq2fOBeXIMs_OziBRsUsATgHgWna0h5M/edit?tab=t.0#heading=h.3rzu21agk2m3
Design Doc: https://docs.google.com/document/d/1h3bcZ4oQAnOu5aGW8Rue0TnbiaW2OXWMaqNKwI6RciE/edit?tab=t.0#heading=h.ipgou4bu0qoj

The linked docs provide much of the context

Feature Flag

COMMCARE_CONNECT for now, but I expect to migrate it to its own flag so that it can be enabled independently of the rest of the connect features.

Safety Assurance

Safety story

Existing messaging paths have automated coverage, and are only minimally modified. The new code is almost entirely self contained and will go through a QA process.

Automated test coverage

QA Plan

No QA ticket yet since it is not finished, but I will add it once it starts.

Migrations

  • The migrations in this code can be safely applied first independently of the code

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@dimagimon dimagimon added the reindex/migration Reindex or migration will be required during or before deploy label Nov 14, 2024
@calellowitz calellowitz added the product/feature-flag Change will only affect users who have a specific feature flag enabled label Nov 14, 2024
@calellowitz calellowitz force-pushed the ce/connect-messaging branch 2 times, most recently from 6a953fa to f22c90d Compare November 14, 2024 21:06
corehq/apps/sms/api.py Show resolved Hide resolved
corehq/apps/sms/api.py Outdated Show resolved Hide resolved
corehq/apps/sms/models.py Show resolved Hide resolved
corehq/apps/sms/models.py Outdated Show resolved Hide resolved
corehq/messaging/scheduling/forms.py Show resolved Hide resolved
corehq/messaging/scheduling/forms.py Outdated Show resolved Hide resolved
@@ -1757,6 +1770,10 @@ def create_form_helper():
def form_choices(self):
return [(form['code'], form['name']) for form in get_form_list(self.domain)]

@property
def can_use_connect(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: is this better than just having the calling code check the feature flag?

@@ -405,3 +407,19 @@ def user_can_access_domain_specific_pages(request):
return False

return couch_user.is_member_of(project) or (couch_user.is_superuser and not project.restrict_superusers)


def connectid_token_auth(view_func):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird that connectid is one word. I do see that it's consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think of connectid as its own thing (its a separate repo and site than connect), using one word feels like it implies that, rather than the id for connect, but I am not wedded to it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connectid and "the id for connect` being two separate concepts sounds confusing, but I don't think I have enough context on the project to be certain or to make a better suggestion.

preserve_default=False,
),
migrations.AddField(
model_name='connectmessagesurveycontent',
name='form_unique_id',
field=models.CharField(default=1, max_length=126),
field=models.CharField(default="1", max_length=126),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just allow this to be blank? Or does 1 have a meaning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this will be unnecessary once we combine the migrations as you mentioned above, we just needed any value to have a valid migration, even though that table was empty when I made this one, so it is never used.

Copy link
Contributor

@snopoke snopoke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this looks good to me but I'm not able to fully review all the implications of the changes.

@@ -76,8 +76,8 @@ def send_first_message(domain, recipient, phone_entry_or_number, session, respon
messaging_subevent_id=logged_subevent.pk
)

if isinstance(phone_entry_or_number, PhoneNumber):
send_sms_to_verified_number(
if isinstance(phone_entry_or_number, PhoneNumber) or isinstance(phone_entry_or_number, ConnectMessagingNumber):
Copy link
Contributor

@pxwxnvermx pxwxnvermx Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this can be simplified as isinstance supports giving it an iterable of types to match.

Suggested change
if isinstance(phone_entry_or_number, PhoneNumber) or isinstance(phone_entry_or_number, ConnectMessagingNumber):
if isinstance(phone_entry_or_number, (PhoneNumber, ConnectMessagingNumber)):

@@ -1565,6 +1576,8 @@ def add_initial_for_content(self, initial):
initial['content'] = self.CONTENT_SMS_CALLBACK
elif isinstance(content, FCMNotificationContent):
initial['content'] = self.CONTENT_FCM_NOTIFICATION
elif isinstance(content, ConnectMessageContent):
initial['conent'] = self.CONTENT_CONNECT_MESSAGE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo 😢

result |= set(content.message)
elif isinstance(content, EmailContent):
elif isinstance(content, (EmailContent)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the () braces around EmailContent required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no


class Meta:
unique_together = ('domain', 'commcare_user')

def get_or_create_key(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be nice as a property that would silently get or create the key.

@orangejenny
Copy link
Contributor

Reviewed through the "update report" commit (c67ac9e)

@orangejenny
Copy link
Contributor

Test failure looks real.

@@ -76,7 +76,7 @@ services:
interval: 10s
retries: 10
volumes:
- ${VOLUME_PREFIX}${BLANK_IF_TESTS-postgresql:}/var/lib/postgresql/data
- ${VOLUME_PREFIX}${BLANK_IF_TESTS-postgresql:}/var/lib/postgresql14/data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidental?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/feature-flag Change will only affect users who have a specific feature flag enabled reindex/migration Reindex or migration will be required during or before deploy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants